package examen.miguel.remirez.struts2;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;


public class DivisaAction extends ActionSupport implements ModelDriven<Divisa> {

	private static final long serialVersionUID = -6659354552584240539L;

	
	private Divisa divisa = new Divisa();
	private List<Divisa> listaDivisa = new ArrayList<Divisa>();
	private DivisaDAO divisaDAO = new DivisaDAO();
	
	
	@Override
	public Divisa getModel() {
		return divisa;
	}
	
	
	public String guardarOActualizar()
	{	
		divisaDAO.guadgarOActualizarDivisa(divisa);
		return SUCCESS;
	}
	
	
	public String listar()
	{
		listaDivisa = divisaDAO.listarDivisas();
		return SUCCESS;
	}
	
	
	public String eliminar()
	{
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		divisaDAO.eliminarDivisa(Long.parseLong(request.getParameter("id")));
		return SUCCESS;
	}
	
	
	public String editar()
	{
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		divisa = divisaDAO.listarDivisaPorId(Long.parseLong(request.getParameter("id")));
		return SUCCESS;
	}
	
	public Divisa getDivisa() {
		return divisa;
	}

	public void setDivisa(Divisa divisa) {
		this.divisa = divisa;
	}

	public List<Divisa> getListaDivisa() {
		return listaDivisa;
	}

	public void setListaDivisa(List<Divisa> listaDivisas) {
		this.listaDivisa = listaDivisas;
	}
	
	

}